package main

import (
	"errors"
	"fmt"
	"iter"
	"slices"
)

func genertetstmain() {
	lst := List[int]{}
	lst.Push(1)
	lst.Push(2)
	lst.Push(3)
	lst.Push(4)
	for e := range lst.All() {
		fmt.Println(e)
	}
	all := slices.Collect(lst.All())
	fmt.Println(all)
	for n := range genFib() {
		if n >= 10 {
			break
		}
		fmt.Println(n)
	}
}

type List[T any] struct {
	head, tail *element[T]
}
type element[T any] struct {
	next, tail *element[T]
	value      T
}

func (ls List[T]) Push(v T) bool {
	if ls.tail == nil {
		ls.head = &element[T]{next: nil, value: v}
		ls.tail = ls.head
	} else {
		ls.tail.next = &element[T]{next: nil, value: v}
		ls.tail = ls.tail.next
		return true
	}
	return true
}
func (ls List[T]) AllElements() []T {
	var result []T
	for e := ls.head; e != nil; e = e.next {
		result = append(result, e.value)
	}
	return result
}
func (ls *List[T]) All() iter.Seq[T] {
	return func(yield func(T) bool) {
		for e := ls.head; e != nil; e = e.next {
			if !yield(e.value) {
				return
			}
		}
	}
}
func genFib() iter.Seq[int] {
	return func(yield func(int) bool) {
		a, b := 1, 1
		for {
			if !yield(a) {
				return
			}
			a, b = b, a+b
		}
	}
}

var ErrorofTea = fmt.Errorf("no more tea available")

func make(arr int) error {
	return ErrorofTea
}
func makea(arr int) error {
	errors.Is(errors.New("no more tea available"), ErrorofTea)
	return errors.New("asddddd")
}

type ksoError struct {
	arg     int
	message string
}

func (e ksoError) Error() string {
	return fmt.Sprintf("%d: %s", e.arg, e.message)
}
func ksoaddgrahlp() error {
	return &ksoError{
		arg:     10,
		message: "kso error ",
	}
}
